package cn.wolfcode.wolf2w.message.service.impl;

import cn.wolfcode.wolf2w.common.redis.service.RedisService;
import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import cn.wolfcode.wolf2w.message.service.ISmsService;
import cn.wolfcode.wolf2w.message.util.SmsUtils;
import org.aspectj.lang.annotation.SuppressAjWarnings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@Service
public class SmsServiceImpl implements ISmsService {

    @Autowired
    private RedisService redisService;

    @Override
    public void sendMessage(String phone) {

        Random random = new Random();
        Integer num = random.nextInt(90000) + 10000;
        System.err.println("验证码：" + num);
//        SmsUtils.sendSmsAli(phone, num.toString());

        String key = RedisKeys.VERIFY_CODE.join(phone);
        redisService.setCacheObject(key,num.toString(),RedisKeys.VERIFY_CODE.getTime(), TimeUnit.SECONDS);
    }
}
